package com.example.learn.hwod;

import java.util.Scanner;

public class _21贪心的商人 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int days = sc.nextInt();

        int[] item = new int[number];
        for (int i = 0; i < number; i++) {
            item[i] = sc.nextInt();
        }
        int[][] item_price = new int[number][days];
        for (int i = 0; i < number; i++) {
            for (int j = 0; j < days; j++) {
                item_price[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < number; i++) {
            for (int j = 0; j < days - 1; j++) {
                ans+=Math.max(item_price[i][j+1]-item_price[i][j],0)*item[i];
            }
        }
        System.out.println(ans);

    }
}
